package com.module.wx.controller;

import java.util.Date;
import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.module.wx.util.Util;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.module.wx.domain.ZzdAppUserInfo;
import com.module.wx.service.IZzdAppUserInfoService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 【请填写功能名称】Controller
 * 
 * @author hezhengxian
 * @date 2023-01-31
 */
@RestController
@RequestMapping("/appUserInfo")
public class ZzdAppUserInfoController extends BaseController
{
    @Autowired
    private IZzdAppUserInfoService zzdAppUserInfoService;

    /**
     * 查询【请填写功能名称】列表
     */
    @RequiresPermissions("wx:appUserInfo:list")
    @GetMapping("/list")
    public TableDataInfo list(ZzdAppUserInfo zzdAppUserInfo)
    {
        startPage();
        List<ZzdAppUserInfo> list = zzdAppUserInfoService.selectZzdAppUserInfoList(zzdAppUserInfo);
        return getDataTable(list);
    }

    /**
     * 导出【请填写功能名称】列表
     */
    @RequiresPermissions("wx:appUserInfo:export")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ZzdAppUserInfo zzdAppUserInfo)
    {
        List<ZzdAppUserInfo> list = zzdAppUserInfoService.selectZzdAppUserInfoList(zzdAppUserInfo);
        ExcelUtil<ZzdAppUserInfo> util = new ExcelUtil<ZzdAppUserInfo>(ZzdAppUserInfo.class);
        util.exportExcel(response, list, "【请填写功能名称】数据");
    }

    /**
     * 获取【请填写功能名称】详细信息
     */
    @RequiresPermissions("wx:appUserInfo:query")
    @GetMapping(value = "/{userId}")
    public AjaxResult getInfo(@PathVariable("userId") String userId)
    {
        return success(zzdAppUserInfoService.selectZzdAppUserInfoByUserId(userId));
    }

    /**
     * 新增【请填写功能名称】
     */
    @RequiresPermissions("wx:appUserInfo:add")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping(value = "/addUser")
    public AjaxResult add(@RequestBody ZzdAppUserInfo zzdAppUserInfo)
    {
        AjaxResult ajax = new AjaxResult();
        if(zzdAppUserInfo.getUserId()==null||zzdAppUserInfo.getUserId().equals("")){
            zzdAppUserInfo.setUserId(Util.get_radom_id());
        }
        zzdAppUserInfo.setCrteTime(new Date());
        ZzdAppUserInfo userInfo = zzdAppUserInfoService.selectZzdAppUserInfoByUserId(zzdAppUserInfo.getUserId());
        // 不为空则证明已经存在该用户信息
        if(userInfo!=null){
            zzdAppUserInfoService.updateZzdAppUserInfo(userInfo);
        }else{
            zzdAppUserInfoService.insertZzdAppUserInfo(zzdAppUserInfo);
        }
        ajax.put("msg","操作成功");
        ajax.put("code",200);
        return ajax;
    }

    /**
     * 修改【请填写功能名称】
     */
    @RequiresPermissions("wx:appUserInfo:edit")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ZzdAppUserInfo zzdAppUserInfo)
    {
        return toAjax(zzdAppUserInfoService.updateZzdAppUserInfo(zzdAppUserInfo));
    }

    /**
     * 删除【请填写功能名称】
     */
    @RequiresPermissions("wx:appUserInfo:remove")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
	@DeleteMapping("/{userIds}")
    public AjaxResult remove(@PathVariable String[] userIds)
    {
        return toAjax(zzdAppUserInfoService.deleteZzdAppUserInfoByUserIds(userIds));
    }
}
